package com.doyens.gmall.product.api;

import com.alibaba.fastjson.JSONObject;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.*;
import com.doyens.gmall.product.service.BaseTrademarkService;
import com.doyens.gmall.product.service.MangeService;
import com.doyens.gmall.product.service.SkuManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Classname:ProductApiController
 * PackageName:com.doyens.gmall.product.api
 *
 * @Author:uyijk
 * @Create:2023/7/28 14:14
 * @Version: 1.0
 */
@RestController
@RequestMapping("api/product")
@Api(tags = "商品管理，内部接口")
public class ProductApiController {
    @Autowired
    private SkuManageService skuManageService;

    @Autowired
    private MangeService mangeService;
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //获取sku信息和图片信息，通过skuId
    @ApiOperation("通过skuId获取sku信息")
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId")Long skuId){
        return skuManageService.getskuInfo(skuId);
    }

    @ApiOperation("获取三级分类")
    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id")Long category3Id){
        return mangeService.getCategoryViewByCategory3Id(category3Id);
    }


    @ApiOperation("根据skuId获取实时价格")
    @GetMapping("inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId")Long skuId){
        return skuManageService.getSkuPrice(skuId);
    }

    @GetMapping("inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable("skuId")Long skuId,@PathVariable("spuId")Long spuId){
        return  skuManageService.getSpuSaleAttrListCheckBySku(skuId,spuId);
    }

    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    //{1|4|7:1},{3|4|7:2}
    public Map getSkuValueIdsMap(@PathVariable("spuId")Long spuId){
        return skuManageService.getSkuValueIdsMap(spuId);
    }

    /**
     * 获取全部分类信息
     * @return
     */
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> list = mangeService.getBaseCategoryList();
        return Result.ok(list);
    }

    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable("tmId")Long tmId){
        return baseTrademarkService.getTrademarkByTmId(tmId);
    }
    /**
     * 通过skuId 集合来查询数据
     * @param skuId
     * @return
     */
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId){
        return skuManageService.getAttrList(skuId);
    }


}
